package com.yzzrjy.controller.mainservlet.blog;

import com.yzzrjy.Service.BlogService;
import com.yzzrjy.util.ResponseUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "UpdateBlogLikedServlet", value = "/updateBlogLiked")
public class UpdateBlogLikedServlet extends HttpServlet {
    private BlogService blogService = new BlogService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String likedUid = request.getParameter("likedUid");
        String token = request.getParameter("token");
        String blogId = request.getParameter("blogId");
        String liked = request.getParameter("liked");
        if(likedUid == null || token == null || blogId == null || liked == null){
            ResponseUtils.parameterError(response);
            return;
        }
        try {
            blogService.updateBlogLiked(blogId, likedUid, Boolean.parseBoolean(liked));
            ResponseUtils.success(response, "success");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
